/**
 * @ author: 汪孟苹
 */
define(["jquery","bbcare","comm/datatable/datatable","bch/app/commSearch/commSearch",
    "bch/app/patientManager/nutritionList.servers","bch/app/patientManager/nutritionList.ui"],function($,$bb,$datatable,$commSearch,$servers,$ui) {
    var nutritionList = {};

    /**
     * 点击添加患者
     */
    var onAddPatient = function(){
        var params = $(this).data("params");
        var arg = {
            "queueId":params.queueId,
            "schemeId":params.schemeId,
            "busiTypeList":params.busiTypeList
        };
        var domId = $(this).attr("id");
        $bb.open(params,domId,"bch_addPatient_hide",arg);
    }

    /**
     * 请求健康情况成功后的回调函数
     */
    var ajaxHealthyCallBack = function(data){
        if( data.rows.length > 0 ){
            $commSearch.ui.healthy({
                "id":"heath",
                "list":data.rows,
            });
        }
    }
    /**
     * 请求录入成功后的回调函数
     */
    var ajaxCreatAuthorCallBack = function(data){
        if( data.rows.length > 0 ){
            $commSearch.ui.creatAuthor({
                "id":"createAuthor",
                "list":data.rows,
            });
        }
    }
    /**
     * 查询路径节点任务信息
     */
    var ajaxTaskNameCallBack = function(data){
        if( data.rows.length > 0 ){
            $commSearch.ui.taskName({
                "id":"seqFrom",
                "list":data.rows,
            });
            $commSearch.ui.taskName({
                "id":"seqTo",
                "list":data.rows,
            });
        }
    }

    nutritionList.init = function(){
        var params = $bb.getPageParams();
        // 添加患者
        $("#addPatient").unbind("click");
        $("#addPatient").data("params",params);
        $("#addPatient").click(onAddPatient);
        // 分类
        var title;
        switch(params.kind){
            case "1":
                title = "蛋白质-能量营养不良";
                break;
            case "2":
                title = "营养性缺铁贫血";
                break;
            case "3":
                title = "维生素D缺乏性佝偻病";
                break;
            case "4":
                title = "超重/肥胖";
                break;
            case "5":
                title = "眼保健管理";
                break;
            case "6":
                title = "听力保健管理";
                break;
            case "7":
                title = "口腔保健管理";
                break;
            case "8":
                title = "心理保健管理";
                break;
        }
        $("#nutritionListTitle").html( title );
        $ui.datatableForm({
            "id":"datatableForm",
            "kind":params.kind
        });
        if( params.kind=="5" || params.kind=="6" || params.kind=="7" || params.kind=="8" ){
            // 健康情况
            $commSearch.servers.ajaxHealthy(ajaxHealthyCallBack);
            // 录入者
            $commSearch.servers.ajaxCreatAuthor(ajaxCreatAuthorCallBack);
            // 访视进度
            var params = $bb.getPageParams();
            var params1 = {
                "busiTypeList":params.busiTypeList,
                "subBusiTypeList":params.subBusiTypeList,
                "schemeId":params.schemeId,
            }
            $commSearch.servers.ajaxTaskName(params1,ajaxTaskNameCallBack);
        }
        $ui.datatableBox({
            "dom":$("#datatable thead tr"),
            "kind":params.kind
        });
        // datatable
        var id = $(".layout-bottom table").attr("id");
        $datatable.init({
            "id": id,
            "options": $servers.getOptions()
        });
    }

    return nutritionList;
});